<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="上课日期" prop="date">
        <el-input
          v-model="queryParams.date"
          placeholder="请输入上课日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上课时间" prop="time">
        <el-input
          v-model="queryParams.time"
          placeholder="请输入上课时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课程名称" prop="courseName">
        <el-input
          v-model="queryParams.courseName"
          placeholder="请输入课程名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级ID" prop="classId">
        <el-input
          v-model="queryParams.classId"
          placeholder="请输入班级ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级名称" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入班级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课时数" prop="courseNum">
        <el-input
          v-model="queryParams.courseNum"
          placeholder="请输入课时数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="授课" prop="teacher">
        <el-input
          v-model="queryParams.teacher"
          placeholder="请输入授课"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生数" prop="studentNum">
        <el-input
          v-model="queryParams.studentNum"
          placeholder="请输入学生数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考勤员" prop="attendanceTeacher">
        <el-input
          v-model="queryParams.attendanceTeacher"
          placeholder="请输入考勤员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课消数" prop="courseCancellations">
        <el-input
          v-model="queryParams.courseCancellations"
          placeholder="请输入课消数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="在读学员" prop="courseNowStudent">
        <el-input
          v-model="queryParams.courseNowStudent"
          placeholder="请输入在读学员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出勤率" prop="attendance">
        <el-input
          v-model="queryParams.attendance"
          placeholder="请输入出勤率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入机构ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注2" prop="remark2">
        <el-input
          v-model="queryParams.remark2"
          placeholder="请输入备注2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注3" prop="remark3">
        <el-input
          v-model="queryParams.remark3"
          placeholder="请输入备注3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注4" prop="remark4">
        <el-input
          v-model="queryParams.remark4"
          placeholder="请输入备注4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注5" prop="remark5">
        <el-input
          v-model="queryParams.remark5"
          placeholder="请输入备注5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注6" prop="remark6">
        <el-input
          v-model="queryParams.remark6"
          placeholder="请输入备注6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注7" prop="remark7">
        <el-input
          v-model="queryParams.remark7"
          placeholder="请输入备注7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注8" prop="remark8">
        <el-input
          v-model="queryParams.remark8"
          placeholder="请输入备注8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注9" prop="remark9">
        <el-input
          v-model="queryParams.remark9"
          placeholder="请输入备注9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注10" prop="remark10">
        <el-input
          v-model="queryParams.remark10"
          placeholder="请输入备注10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['classrecords:classrecords:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['classrecords:classrecords:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['classrecords:classrecords:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['classrecords:classrecords:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="classrecordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="上课日期" align="center" prop="date" />
      <el-table-column label="上课时间" align="center" prop="time" />
      <el-table-column label="课程名称" align="center" prop="courseName" />
      <el-table-column label="班级ID" align="center" prop="classId" />
      <el-table-column label="班级名称" align="center" prop="className" />
      <el-table-column label="课时数" align="center" prop="courseNum" />
      <el-table-column label="授课" align="center" prop="teacher" />
      <el-table-column label="学生数" align="center" prop="studentNum" />
      <el-table-column label="考勤员" align="center" prop="attendanceTeacher" />
      <el-table-column label="课消数" align="center" prop="courseCancellations" />
      <el-table-column label="在读学员" align="center" prop="courseNowStudent" />
      <el-table-column label="出勤率" align="center" prop="attendance" />
      <el-table-column label="机构ID" align="center" prop="deptId" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注2" align="center" prop="remark2" />
      <el-table-column label="备注3" align="center" prop="remark3" />
      <el-table-column label="备注4" align="center" prop="remark4" />
      <el-table-column label="备注5" align="center" prop="remark5" />
      <el-table-column label="备注6" align="center" prop="remark6" />
      <el-table-column label="备注7" align="center" prop="remark7" />
      <el-table-column label="备注8" align="center" prop="remark8" />
      <el-table-column label="备注9" align="center" prop="remark9" />
      <el-table-column label="备注10" align="center" prop="remark10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['classrecords:classrecords:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['classrecords:classrecords:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改上课记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="上课日期" prop="date">
          <el-input v-model="form.date" placeholder="请输入上课日期" />
        </el-form-item>
        <el-form-item label="上课时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入上课时间" />
        </el-form-item>
        <el-form-item label="课程名称" prop="courseName">
          <el-input v-model="form.courseName" placeholder="请输入课程名称" />
        </el-form-item>
        <el-form-item label="班级ID" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入班级ID" />
        </el-form-item>
        <el-form-item label="班级名称" prop="className">
          <el-input v-model="form.className" placeholder="请输入班级名称" />
        </el-form-item>
        <el-form-item label="课时数" prop="courseNum">
          <el-input v-model="form.courseNum" placeholder="请输入课时数" />
        </el-form-item>
        <el-form-item label="授课" prop="teacher">
          <el-input v-model="form.teacher" placeholder="请输入授课" />
        </el-form-item>
        <el-form-item label="学生数" prop="studentNum">
          <el-input v-model="form.studentNum" placeholder="请输入学生数" />
        </el-form-item>
        <el-form-item label="考勤员" prop="attendanceTeacher">
          <el-input v-model="form.attendanceTeacher" placeholder="请输入考勤员" />
        </el-form-item>
        <el-form-item label="课消数" prop="courseCancellations">
          <el-input v-model="form.courseCancellations" placeholder="请输入课消数" />
        </el-form-item>
        <el-form-item label="在读学员" prop="courseNowStudent">
          <el-input v-model="form.courseNowStudent" placeholder="请输入在读学员" />
        </el-form-item>
        <el-form-item label="出勤率" prop="attendance">
          <el-input v-model="form.attendance" placeholder="请输入出勤率" />
        </el-form-item>
        <el-form-item label="机构ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入机构ID" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="remark2">
          <el-input v-model="form.remark2" placeholder="请输入备注2" />
        </el-form-item>
        <el-form-item label="备注3" prop="remark3">
          <el-input v-model="form.remark3" placeholder="请输入备注3" />
        </el-form-item>
        <el-form-item label="备注4" prop="remark4">
          <el-input v-model="form.remark4" placeholder="请输入备注4" />
        </el-form-item>
        <el-form-item label="备注5" prop="remark5">
          <el-input v-model="form.remark5" placeholder="请输入备注5" />
        </el-form-item>
        <el-form-item label="备注6" prop="remark6">
          <el-input v-model="form.remark6" placeholder="请输入备注6" />
        </el-form-item>
        <el-form-item label="备注7" prop="remark7">
          <el-input v-model="form.remark7" placeholder="请输入备注7" />
        </el-form-item>
        <el-form-item label="备注8" prop="remark8">
          <el-input v-model="form.remark8" placeholder="请输入备注8" />
        </el-form-item>
        <el-form-item label="备注9" prop="remark9">
          <el-input v-model="form.remark9" placeholder="请输入备注9" />
        </el-form-item>
        <el-form-item label="备注10" prop="remark10">
          <el-input v-model="form.remark10" placeholder="请输入备注10" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listClassrecords, getClassrecords, delClassrecords, addClassrecords, updateClassrecords } from "@/api/classrecords/classrecords";

export default {
  name: "Classrecords",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 上课记录表格数据
      classrecordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        date: null,
        time: null,
        courseName: null,
        classId: null,
        className: null,
        courseNum: null,
        teacher: null,
        studentNum: null,
        attendanceTeacher: null,
        courseCancellations: null,
        courseNowStudent: null,
        attendance: null,
        deptId: null,
        remark2: null,
        remark3: null,
        remark4: null,
        remark5: null,
        remark6: null,
        remark7: null,
        remark8: null,
        remark9: null,
        remark10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询上课记录列表 */
    getList() {
      this.loading = true;
      listClassrecords(this.queryParams).then(response => {
        this.classrecordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        date: null,
        time: null,
        courseName: null,
        classId: null,
        className: null,
        courseNum: null,
        teacher: null,
        studentNum: null,
        attendanceTeacher: null,
        courseCancellations: null,
        courseNowStudent: null,
        attendance: null,
        deptId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        remark2: null,
        remark3: null,
        remark4: null,
        remark5: null,
        remark6: null,
        remark7: null,
        remark8: null,
        remark9: null,
        remark10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加上课记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getClassrecords(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改上课记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateClassrecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addClassrecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除上课记录编号为"' + ids + '"的数据项？').then(function() {
        return delClassrecords(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('classrecords/classrecords/export', {
        ...this.queryParams
      }, `classrecords_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
